define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'nursery/wantbuy/index' + location.search,
                    add_url: 'nursery/wantbuy/add',
                    edit_url: 'nursery/wantbuy/edit',
                    del_url: 'nursery/wantbuy/del',
                    multi_url: 'nursery/wantbuy/multi',
                    import_url: 'nursery/wantbuy/import',
                    table: 'nursery_wantbuy',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'introduction', title: __('Introduction'), operate: 'LIKE'},
                        {field: 'lvl', title: __('Lvl'), searchList: {"1":__('Lvl 1'),"2":__('Lvl 2'),"3":__('Lvl 3'),"4":__('Lvl 4')}, formatter: Table.api.formatter.normal},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE'},
                        {field: 'num', title: __('Num')},
                        {field: 'effective_time', title: __('Effective_time'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        // {field: 'lng', title: __('Lng'), operate: 'LIKE'},
                        // {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'browse_num', title: __('Browse_num')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'),
                            table: table,
                            buttons :[
                                {name: 'detail', text: '报价列表', title: '报价列表', icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: 'nursery/wantbuyoffer/index'}
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
